/*  1:   */ package org.jetbrains.io;
/*  2:   */ 
/*  3:   */

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.jetbrains.annotations.Nullable;

/*  4:   */
/*  5:   */
/*  6:   */
/*  7:   */
/*  8:   */
/*  9:   */
/* 10:   */
/* 11:   */ 
/* 12:   */ public abstract class Decoder
/* 13:   */   extends SimpleChannelInboundHandler<ByteBuf>
/* 14:   */ {
/* 15:   */   protected ByteBuf cumulation;
/* 16:   */   
/* 17:   */   protected Decoder()
/* 18:   */   {
/* 19:28 */     super(false);
/* 20:   */   }
/* 21:   */   
/* 22:   */   @Nullable
/* 23:   */   protected final ByteBuf getBufferIfSufficient(ByteBuf paramByteBuf, int paramInt, ChannelHandlerContext paramChannelHandlerContext)
/* 24:   */   {
/* 25:33 */     if (!paramByteBuf.isReadable()) {
/* 26:34 */       return null;
/* 27:   */     }
/* 28:37 */     if (this.cumulation == null)
/* 29:   */     {
/* 30:38 */       if (paramByteBuf.readableBytes() < paramInt)
/* 31:   */       {
/* 32:39 */         this.cumulation = paramChannelHandlerContext.channel().config().getAllocator().buffer(paramInt);
/* 33:40 */         this.cumulation.writeBytes(paramByteBuf);
/* 34:41 */         return null;
/* 35:   */       }
/* 36:44 */       return paramByteBuf;
/* 37:   */     }
/* 38:48 */     if (this.cumulation.readableBytes() + paramByteBuf.readableBytes() < paramInt)
/* 39:   */     {
/* 40:49 */       this.cumulation.writeBytes(paramByteBuf);
/* 41:50 */       return null;
/* 42:   */     }
/* 43:53 */     ByteBuf localByteBuf = Unpooled.wrappedBuffer(new ByteBuf[] { this.cumulation, paramByteBuf });
/* 44:54 */     paramByteBuf.skipBytes(paramByteBuf.readableBytes());
/* 45:55 */     this.cumulation = null;
/* 46:56 */     return localByteBuf;
/* 47:   */   }
/* 48:   */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.io.Decoder

 * JD-Core Version:    0.7.0.1

 */